
#ifndef _CHARACTER_MODULE_H_
#define _CHARACTER_MODULE_H_
#include "stm32_smart_card.h"

#define DIRECT_BYTE		0
#define REVERSE_BYTE	1

struct character_module_tag
{
	hardware_module_t *hw;
	uint8_t retransmit_times;
	uint8_t byte_direction;
	uint8_t FiDi;
	uint16_t opposite_guardtime;
	uint8_t transmit_direction;
};	

typedef struct character_module_tag character_module_t;


void CharacterModule_SetETU(character_module_t *module, uint8_t FiDi);
void CharacterModule_SetStopbits(character_module_t *module, uint8_t stopbits);
void CharacterModule_SetOppositiveGuardtime(character_module_t *module, uint16_t opposite_guardtime);

void CharacterModule_SetByteDirect(character_module_t *module);
void CharacterModule_SetByteReverse(character_module_t * module);
void CharacterModule_ConfigByteDirection(character_module_t *module, uint8_t direction);
uint8_t CharacterModule_SendByte(character_module_t *module, uint8_t byte, uint32_t guard_time);
uint8_t CharacterModule_SendData(character_module_t *module, 
					uint8_t *data, uint32_t data_len, uint32_t guard_time);
uint8_t CharacterModule_ReceiveByte(character_module_t *module, uint8_t *receive_byte);
uint8_t CharacterModule_ReceiveData(character_module_t *module, 
					uint8_t *receive_buf, uint32_t receive_len, uint32_t wait_time);
					
void CharacterModule_TimerDelay(character_module_t *module, uint32_t etu);
void CharacterModule_TimerStart(character_module_t *module, uint32_t etu);
void CharacterModule_TimerReset(character_module_t *module);
void CharacterModule_TimerStop(character_module_t *module);
void CharacterModule_ConfigRetransmit(character_module_t *module, uint8_t retransmit_times);
uint8_t CharacterModule_IsRetransmitEnable(character_module_t *module);

void CharacterModule_Init(void);
void CharacterModule_Flush(character_module_t *module);
void CharacterModule_Reset(character_module_t *module);

#endif

